package entity

import (
	"fmt"

	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//IndiZjywSgbl 零售中收
type IndiZjywSgbl struct {
	ID int `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	// DTID  time.Time `gorm:"column:DTID"`  //导入日期
	JJYF   string  `gorm:"column:JJYF"`
	EMNO1  string  `gorm:"column:EMNO1"`
	EMID1  int     `gorm:"column:EMID1"`
	EMNM1  string  `gorm:"-" json:"emnm1"`
	DSVL1  float64 `gorm:"column:DSVL1"`
	EMNM   string  `gorm:"column:EMNM"`
	CFLC   float64 `gorm:"column:CFLC"`
	CFJJ   float64 `gorm:"column:CFJJ"`
	CFBX   float64 `gorm:"column:CFBX"`
	CFGJS  float64 `gorm:"column:CFGJS"`
	CFSFDX float64 `gorm:"column:CFSFDX"`
	XYK    float64 `gorm:"column:XYK"`
	WD     float64 `gorm:"column:WD"`
	GDFX   float64 `gorm:"column:GDFX"`
	QT     float64 `gorm:"column:QT"`
	ZSHJ   float64 `gorm:"column:ZSHJ"`
}

//TableName  零售中收导入
func (IndiZjywSgbl) TableName() string {
	return "T_INDI_ZJYW_SGBL"

}

//IndiZjywSgblEF 返回结构体
func IndiZjywSgblEF() base.EntityFunc {
	return func() interface{} {
		entity := IndiZjywSgbl{}
		return &entity
	}
}

//IndiZjywSgblESF 返回结构体数组
func IndiZjywSgblESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []IndiZjywSgbl
		return &entities
	}
}

//BeforeSave 保存前的触发器
func (i *IndiZjywSgbl) BeforeSave(tx *gorm.DB) (err error) {
	sqlEx := "select dbo.GetBackDATE()"
	row := tx.Raw(sqlEx).Row()

	var emid1 int
	sqlEx = "select ID from T_SysUser where SysUserID=?"
	row = tx.Raw(sqlEx, i.EMNO1).Row()
	row.Scan(&emid1)
	if emid1 == 0 {
		return fmt.Errorf("员工号1:%s在系统中没有找到！", i.EMNO1)
	}

	return

}

func init() {
	base.DaoPoolObj.Put("IndiZjywSgbl", base.NewDefaultDao(IndiZjywSgblEF(), IndiZjywSgblESF(), nil))

}
